﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TeacherHelp.FormList.Student
{

    public partial class StartTestForm : Form
    {
        private ExercisesInfoForm _exercisesInfoForm = null;
        public StudentMainForm _studentMainForm = null;

        public int? _subjectsId = null;

        /// <summary>
        /// 考试开始时间
        /// </summary>
        public DateTime? _startTime = null;

        /// <summary>
        /// 交卷
        /// </summary>
        protected internal void SubmitDollors(bool isHint = false)
        {
            if (isHint)
            {
                var isExit = MessageBox.Show("确定要交卷么？", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                if (isExit == DialogResult.Cancel) return;
            }

            _exercisesInfoForm.Close();
            _studentMainForm.child_ShowForm(new TestResult(_exercisesInfoForm._testExercise, _startTime, DateTime.Now, _subjectsId));
        }

        private StartTestForm()
        {
            InitializeComponent();
        }

        public StartTestForm(StudentMainForm studentMainForm) : this()
        {
            this._studentMainForm = studentMainForm;
        }

        private void StartTestForm_Load(object sender, EventArgs e)
        {
            BLL.SubjectsManager subjectsManager = new BLL.SubjectsManager();
            this.SubjectSelectComBox.DataSource = subjectsManager.GetSubjectsCount50();
            this.SubjectSelectComBox.ValueMember = nameof(Model.Subjects.Id);
            this.SubjectSelectComBox.DisplayMember = nameof(Model.Subjects.Name);
        }

        private void StartTestBtn_Click(object sender, EventArgs e)
        {
            _subjectsId = this.SubjectSelectComBox.SelectedValue.ToInt();
            _exercisesInfoForm = new ExercisesInfoForm(this);
            _startTime = DateTime.Now;
            _exercisesInfoForm.Show();
        }

    }
}
